package com.qf.ssm.controller;

import com.qf.ssm.entity.Brand;
import com.qf.ssm.service.SelectListService;
import com.qf.ssm.utils.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {
    @Resource
    SelectListService listService;


    /**
     * 展示所有的品牌的数据
     *
     * @return
     */
    @GetMapping("/selectList")
    private ResponseResult<List<Brand>> selectList() {
        //return ResponseResult.success(propertyGroupService.selectDefaultDisplay());
        return ResponseResult.success(listService.selectList());
    }

    /**
     * 通过id来进行一对多的查询
     *
     * @return
     */
    @GetMapping("/selectByIdList")
    private ResponseResult<List<Brand>> selectByIdList(int id) {

        return ResponseResult.success(listService.selectByIdList(id));
    }

    /**
     * 通过ID来删除某个品牌的接口
     */
    @PutMapping("/updateById")
    private ResponseResult<Integer> updateById(int id) {
        return ResponseResult.success(listService.updateById(id));
    }

    /**
     * 批量删除的接口
     */
    @GetMapping("/updateList")
    private ResponseResult<Integer> updateList(List<Integer> ids) {
        return ResponseResult.success(listService.updateList(ids));

    }

    /**
     * 通过名字来查询详细信息
     * @param name
     * @return
     */

    @GetMapping("/selectByName")
    private ResponseResult<Brand> selectByName(String name) {
        return ResponseResult.success(listService.selectByName(name));
    }
    /**
     * 新增品牌的接口
     */
    @PostMapping("/insertNewBrand")
    private ResponseResult<Integer>insertNewBrand(@RequestBody Brand brand){
        return ResponseResult.success(listService.insertNewBrand(brand));
    }

}
